/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.nicmodule.services;

import org.testis.nicmodule.core.NetworkInterfaceController;
import org.testis.data.TestStepException;
import org.testis.data.TestStepResultType;
import org.testis.services.AtofModuleAction;
import org.testis.services.AtofModuleService;
import java.lang.reflect.Constructor;
import org.testis.logging.LogSenderService;
import org.testis.logging.AtofLogLevel;
import org.testis.nicmodule.core.NetworkInterfaceControllerFactory;
import org.testis.nicmodule.data.NicModuleDataObject;
import org.testis.nicmodule.core.NicModuleException;
import java.lang.reflect.InvocationTargetException;


/**main method for dhcp renewing
 *
 * @author root
 */
public class NicModuleRenewDhcpConfigurationAction extends AtofModuleAction
{

    @Override
    public boolean operateRequest(AtofModuleService request)
    {

        NetworkInterfaceController tmpObject;
        NicModuleDataObject dataObj = (NicModuleDataObject) request.getDataObj();
        try {

            LogSenderService.putMessageOnQueue(
                "NicModuleRenewDhcpConfigurationAction",
                AtofLogLevel.INFO,
                "Renew DHCP configuration requested",
                dataObj.getMessageId());

            String iFace = dataObj.getParamInterface();
            String iModule = dataObj.getParamModule();
            tmpObject = NetworkInterfaceControllerFactory.createInstance(iModule,
                                                                         iFace);
            boolean result = tmpObject.renewDhcpConfiguration();
            AtofLogLevel level = result ? AtofLogLevel.INFO : AtofLogLevel.ERROR;
            LogSenderService.putMessageOnQueue(
                "NicModuleRenewDhcpConfigurationAction",
                level,
                "RenewDhcpConfiguration resulted:" +
                Boolean.valueOf(result),
                dataObj.getMessageId());

            return result;

        } catch (IllegalArgumentException ex) {
            throw new TestStepException(TestStepResultType.FAILURE,
                                        "Execution of NicModuleRenewDhcpConfigurationAction failed..." +
                                        ex.getMessage());

        } catch (InvocationTargetException ex) {
            throw new TestStepException(TestStepResultType.FAILURE,
                                        "Execution of NicModuleRenewDhcpConfigurationAction failed..." +
                                        ex.getMessage());

        } catch (InstantiationException ex) {
            throw new TestStepException(TestStepResultType.FAILURE,
                                        "Execution of NicModuleRenewDhcpConfigurationAction failed..." +
                                        ex.getMessage());
        } catch (IllegalAccessException ex) {
            throw new TestStepException(TestStepResultType.FAILURE,
                                        "Execution of NicModuleRenewDhcpConfigurationAction failed..." +
                                        ex.getMessage());

        } catch (ClassNotFoundException ex) {
            throw new TestStepException(TestStepResultType.FAILURE,
                                        "Execution of NicModuleRenewDhcpConfigurationAction failed..." +
                                        ex.getMessage());
        } catch (NicModuleException ex) {
            throw new TestStepException(TestStepResultType.MISTAKE,
                                        "Execution of NicModuleRenewDhcpConfigurationAction due to NicmoduleException..." +
                                        ex.getMessage());
        }

    }
}
